import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/tools_base/widget/common_dialog.dart';

import '../../../assets_tool/app_colors.dart';
import '../../../hj_utils/screen.dart';
import '../../../hj_utils/widget_utils.dart';

class CommonAlert extends StatelessWidget {
  final String? title;
  final String? desc;
  final String? leftBtn;
  final String? rightBtn;
  final Widget? contentChild;
  final bool? showLeftButton;

  CommonAlert({
    super.key,
    this.title = '温馨提示',
    this.desc = '',
    this.leftBtn = '取消',
    this.rightBtn = '确定',
    this.contentChild,
    this.showLeftButton = true,
  });

  @override
  Widget build(BuildContext context) {
    return CommonDialog(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            title ?? '',
            style: textStyle(20, Color(0xE5FFFFFF), FontWeight.w500),
          ),
          12.sizeBoxH,
          0.5.line,
          12.sizeBoxH,
          contentChild ??
              Text(
                desc ?? '',
                style: textStyle(14, Color(0x73FFFFFF), FontWeight.w400),
              ),
          24.sizeBoxH,
          Container(
            height: 46,
            child: Row(
              children: [
                if (showLeftButton == true) ...[
                  Expanded(
                    child: greyDarkBtn(leftBtn ?? '', () => Get.back(result: false), width: (screen.screenWidth - 110) / 2),
                  ),
                  20.sizeBoxW,
                ],
                Expanded(
                  child: redBtn(rightBtn ?? '', () => Get.back(result: true), width: (screen.screenWidth - 110) / 2),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  //红色按钮
  Widget redBtn(
    String name,
    void Function()? onTap, {
    double width = 244,
    double height = 46,
    int fontSize = 16,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        width: width.w,
        height: height.w,
        decoration: BoxDecoration(color: AppColors.primaryXColor, borderRadius: BorderRadius.circular(3)),
        child: Text(
          name,
          style: TextStyle(color: Colors.white, fontWeight: FontWeight.w500, fontSize: fontSize.sp),
        ),
      ),
    );
  }

//灰色按钮
  Widget greyBtn(
    String name,
    void Function()? onTap, {
    double width = 244,
    double height = 46,
    int fontSize = 16,
    double borderWidth = 1.0,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        width: width.w,
        height: height.w,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(3), border: Border.all(width: borderWidth, color: Color(0xff989898))),
        child: Text(
          name,
          style: TextStyle(color: Color(0xff989898), fontWeight: FontWeight.w500, fontSize: fontSize.sp),
        ),
      ),
    );
  }

//灰色按钮
  Widget greyDarkBtn(
    String name,
    void Function()? onTap, {
    double width = 244,
    double height = 46,
    int fontSize = 16,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        width: width.w,
        height: height.w,
        decoration: BoxDecoration(
          color: Colors.white.withOpacity(0.3),
          borderRadius: BorderRadius.circular(3),
        ),
        child: Text(
          name,
          style: TextStyle(color: Colors.white, fontSize: fontSize.sp, fontWeight: FontWeight.w500),
        ),
      ),
    );
  }
}
